//
//  NavigationMapVC.m
//  YueYueSpecailCarDriver
//
//  Created by 李亚军 on 17/2/24.
//  Copyright © 2017年 黄旺鑫. All rights reserved.
//

#import "NavigationMap.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapNaviKit/AMapNaviKit.h>
#import <QXDriverConfiguration/QXDriverConfiguration.h>
#import "HeaderMacro.h"

@interface NavigationMap ()<AMapNaviDriveManagerDelegate , AMapNaviDriveViewDelegate>


@end

@implementation NavigationMap


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    // 导航
    [self initDriveManager];
    [self configureUI];
}


/**
 配置UI
 */
- (void)configureUI {
    
    self.browseRouteButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.browseRouteButton.frame = CGRectMake(15, self.view.frame.size.height - 65, 35, 35);
    self.browseRouteButton.backgroundColor = [UIColor clearColor];
    [self.browseRouteButton setImage:[QXDriverConfiguration imageWithName:@"public_map_dingwei"] forState:(UIControlStateNormal)];
    [self.browseRouteButton addTarget:self action:@selector(browseRouteAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.browseRouteButton];
    
    
    self.trafficButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.trafficButton.frame = CGRectMake(CGRectGetMinX(self.browseRouteButton.frame), CGRectGetMinY(self.browseRouteButton.frame) - 50, 35, 35);
    self.trafficButton.backgroundColor = [UIColor clearColor];
    [self.trafficButton setImage:[QXDriverConfiguration imageWithName:@"public_map_lukuang"] forState:(UIControlStateNormal)];
    [self.trafficButton addTarget:self action:@selector(showTrafficaAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.trafficButton];
    
}

#pragma mark - 配置导航: 创建 AMapNaviDriveManager
- (void)initDriveManager
{
    if (self.driveManager == nil)
    {
        self.driveManager = [[AMapNaviDriveManager alloc] init];
        [self.driveManager setDelegate:self];
    }
    
    if (self.driveManager != nil) {
        
        [self initNaviDriveView];
    }
}


#pragma mark - 创建: AMapNaviDriveView
- (void)initNaviDriveView {
    
    if (self.driveView == nil)
    {
        self.driveView = [[AMapNaviDriveView alloc] initWithFrame:self.view.bounds];
        self.driveView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        [self.driveView setDelegate:self];
        [self.driveView setShowUIElements:NO];
        if (self.orderState == OrderState_GoToPickUpPassenger || self.orderState == OrderState_ArriveAtThePlaceOfDeparture) {
            
            [self.driveView setEndPointImage:[QXDriverConfiguration imageWithName:@"public_pic_qidian"]];
        }else {
            
            [self.driveView setEndPointImage:[QXDriverConfiguration imageWithName:@"public_pic_zhongdian"]];
        }
        
        [self.driveView setMapZoomLevel:16.0];
        [self.driveView setCameraDegree:0.0];
        self.driveView.trackingMode = AMapNaviViewTrackingModeCarNorth;
        self.driveView.showMode = AMapNaviDriveViewShowModeCarPositionLocked;
        
    }
    
    if (self.driveView != nil) {
        
        [self configureUI];
    }
}


#pragma mark - 将 AMapNaviDriveView 与 AMapNaviManager 关联起来，并将 AManNaviDriveView 显示出来
- (void)configDriveNavi
{
    [self.driveManager addDataRepresentative:self.driveView];
    [self.driveView setShowUIElements:NO];
    [self.view addSubview:self.driveView];    
    if (!self.driveManager.startEmulatorNavi) {
        
        [self.driveManager resumeNavi];
    }
}





#pragma mark - 是否能全览显示
- (void)browseRouteAction:(UIButton *)sender {
    
    // 是否显示全览模式
    [self.driveView setShowMode:(AMapNaviDriveViewShowModeOverview)];
}

#pragma mark - 是否显示交通
- (void)showTrafficaAction:(UIButton *)sender {
    
    //是否显示实时交通路况
    [self.driveView setShowTrafficLayer:!self.driveView.showTrafficLayer];
}


@end
